<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FreeRTOS Addons: cpp_freertos::MemoryPool Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">FreeRTOS Addons
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.5 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacecpp__freertos.html">cpp_freertos</a></li><li class="navelem"><a class="el" href="classcpp__freertos_1_1_memory_pool.html">MemoryPool</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classcpp__freertos_1_1_memory_pool-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">cpp_freertos::MemoryPool Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p><code>#include &lt;<a class="el" href="mem__pool_8hpp_source.html">mem_pool.hpp</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a5f5b240d0720de0a1db06730a4d1ba2c"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcpp__freertos_1_1_memory_pool.html#a5f5b240d0720de0a1db06730a4d1ba2c">MemoryPool</a> (int itemSize, int itemCount, int alignment)</td></tr>
<tr class="separator:a5f5b240d0720de0a1db06730a4d1ba2c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a26b406b6d14ea038989833c669ac7fd5"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcpp__freertos_1_1_memory_pool.html#a26b406b6d14ea038989833c669ac7fd5">MemoryPool</a> (int itemSize, void *preallocatedMemory, int preallocatedMemorySize, int alignment)</td></tr>
<tr class="separator:a26b406b6d14ea038989833c669ac7fd5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3a45774c8c0f761ea8b75e3e4d3a1591"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcpp__freertos_1_1_memory_pool.html#a3a45774c8c0f761ea8b75e3e4d3a1591">AddMemory</a> (int itemCount)</td></tr>
<tr class="separator:a3a45774c8c0f761ea8b75e3e4d3a1591"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:abc987382be536cc5111a38202301a042"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcpp__freertos_1_1_memory_pool.html#abc987382be536cc5111a38202301a042">AddMemory</a> (void *preallocatedMemory, int preallocatedMemorySize)</td></tr>
<tr class="separator:abc987382be536cc5111a38202301a042"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a109b992270d9845d80b4cdb404dbd10f"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcpp__freertos_1_1_memory_pool.html#a109b992270d9845d80b4cdb404dbd10f">Allocate</a> ()</td></tr>
<tr class="separator:a109b992270d9845d80b4cdb404dbd10f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9756d53a0991b842c7d6b5b3393765f8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcpp__freertos_1_1_memory_pool.html#a9756d53a0991b842c7d6b5b3393765f8">Free</a> (void *item)</td></tr>
<tr class="separator:a9756d53a0991b842c7d6b5b3393765f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Memory Pools are fixed size allocations to prevent fragmentation.</p>
<p >This is a new feature to FreeRTOS Wrappers and is not in and of itself a wrapper.</p>
<p >Memory Pools are thread safe, but cannot be used in ISR context. The OS must be running, because these use Mutexes to protect internal data structures. </p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a5f5b240d0720de0a1db06730a4d1ba2c" name="a5f5b240d0720de0a1db06730a4d1ba2c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5f5b240d0720de0a1db06730a4d1ba2c">&#9670;&#160;</a></span>MemoryPool() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">MemoryPool::MemoryPool </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>itemSize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>itemCount</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>alignment</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p >Constructor to create a Memory Pool.</p>
<p >This constructor uses the system malloc to actually obtain the memory.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">itemSize</td><td>How big is each item you want to allocate. </td></tr>
    <tr><td class="paramname">itemCount</td><td>How many items max do you want to allocate at once. </td></tr>
    <tr><td class="paramname">Alignment</td><td>Power of 2 value denoting on which address boundary the memory will be aligned to. Must be at least sizeof(unsigned char *). </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname"><a class="el" href="classcpp__freertos_1_1_memory_pool_malloc_exception.html">MemoryPoolMallocException</a></td><td>on failure. </td></tr>
    <tr><td class="paramname"><a class="el" href="classcpp__freertos_1_1_memory_pool_bad_alignment_exception.html">MemoryPoolBadAlignmentException</a></td><td>on failure. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a26b406b6d14ea038989833c669ac7fd5" name="a26b406b6d14ea038989833c669ac7fd5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a26b406b6d14ea038989833c669ac7fd5">&#9670;&#160;</a></span>MemoryPool() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">MemoryPool::MemoryPool </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>itemSize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>preallocatedMemory</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>preallocatedMemorySize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>alignment</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p >Constructor to create a Memory Pool.</p>
<p >This constructor uses memory you pass in to actually create the pool. This constructor does not throw.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">itemSize</td><td>How big is each item you want to allocate. </td></tr>
    <tr><td class="paramname">preallocatedMemory</td><td>Pointer to the preallocated memory you are dedicating to this pool. </td></tr>
    <tr><td class="paramname">preallocatedMemorySize</td><td>How big is the buffer you are passing in. </td></tr>
    <tr><td class="paramname">Alignment</td><td>Power of 2 value denoting on which address boundary the memory will be aligned to. Must be at least sizeof(unsigned char *). </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname"><a class="el" href="classcpp__freertos_1_1_memory_pool_bad_alignment_exception.html">MemoryPoolBadAlignmentException</a></td><td>on failure. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a3a45774c8c0f761ea8b75e3e4d3a1591" name="a3a45774c8c0f761ea8b75e3e4d3a1591"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3a45774c8c0f761ea8b75e3e4d3a1591">&#9670;&#160;</a></span>AddMemory() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void MemoryPool::AddMemory </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>itemCount</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p >Allows you to add memory to a <a class="el" href="classcpp__freertos_1_1_memory_pool.html">MemoryPool</a>.</p>
<p >Items will be the same size as you initially asked for.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">itemCount</td><td>How many more items max do you want to allocate </td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname"><a class="el" href="classcpp__freertos_1_1_memory_pool_malloc_exception.html">MemoryPoolMallocException</a></td><td>on failure. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="abc987382be536cc5111a38202301a042" name="abc987382be536cc5111a38202301a042"></a>
<h2 class="memtitle"><span class="permalink"><a href="#abc987382be536cc5111a38202301a042">&#9670;&#160;</a></span>AddMemory() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void MemoryPool::AddMemory </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>preallocatedMemory</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>preallocatedMemorySize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p >Allows you to add memory to a <a class="el" href="classcpp__freertos_1_1_memory_pool.html">MemoryPool</a>.</p>
<p >Items will be the same size as you initially asked for.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">preallocatedMemory</td><td>Pointer to the preallocated memory you are dedicating to this pool. </td></tr>
    <tr><td class="paramname">preallocatedMemorySize</td><td>How big is the buffer you are passing in. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a109b992270d9845d80b4cdb404dbd10f" name="a109b992270d9845d80b4cdb404dbd10f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a109b992270d9845d80b4cdb404dbd10f">&#9670;&#160;</a></span>Allocate()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * MemoryPool::Allocate </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p >Allocate an item from the pool.</p>
<dl class="section return"><dt>Returns</dt><dd>Pointer of the memory or NULL if the pool is empty. </dd></dl>

</div>
</div>
<a id="a9756d53a0991b842c7d6b5b3393765f8" name="a9756d53a0991b842c7d6b5b3393765f8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9756d53a0991b842c7d6b5b3393765f8">&#9670;&#160;</a></span>Free()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void MemoryPool::Free </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>item</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p >Returns the item back to it's pool.</p>
<dl class="section note"><dt>Note</dt><dd>There is no checking that the item is actually valid to be returned to this pool. </dd></dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>src/<a class="el" href="mem__pool_8hpp_source.html">mem_pool.hpp</a></li>
<li>src/freertos-addon/c++/cmem_pool.cpp</li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5
</small></address>
</body>
</html>
